package com.game;

import jmp123.PlayBack;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.io.File;
import java.util.Random;


public class Music {
    private static Clip start;
    private static Clip over;
    private static Clip succeed;
    //基尼太美
    private static Clip start2;
    private static Clip move;
    private static Clip attack;
    //鸡
    private static Clip attack2;
    //忽略
    private static Clip attack3;
    private static Clip explode;

    private static Clip explode2;
    private static Clip explode3;
    private static Clip explode4;
    private static Clip explode5;
    private static Clip explode6;
    private static Clip explode7;
    private static Clip explode8;
    private static Clip explode9;
    private static Clip wall;

    static PlayBack gameOver = new PlayBack(new jmp123.output.Audio());
    static String overUrl = "musics/你干嘛哎哟.mp3";

    static PlayBack gameSucceed = new PlayBack(new jmp123.output.Audio());
    static String succeedUrl = "musics/小萝莉笑声.mp3";


    static {
        File bgMusicStartFile = new File("E:\\JAVA IDEA\\各种小项目\\坦克大战\\tankwar\\musics\\bgm.wav");
        File bgMusicStartFile2 = new File("E:\\JAVA IDEA\\各种小项目\\坦克大战\\tankwar\\musics\\鸡你太美.wav");
        File bgMusicOverFile = new File("musics/你干嘛哎哟.wav");
        File bgMusicSucceedFile = new File("musics/小萝莉笑声.wav");
        File bgMusicAttackFile = new File("E:\\JAVA IDEA\\各种小项目\\坦克大战\\tankwar\\musics\\attack.wav");
        File bgMusicAttackFile2 = new File("E:\\JAVA IDEA\\各种小项目\\坦克大战\\tankwar\\musics\\鸡.wav");
        File bgMusicAttackFile3 = new File("musics/老六/你家吗.wav");
        File bgMusicMoveFile = new File("E:\\JAVA IDEA\\各种小项目\\坦克大战\\tankwar\\musics\\move.wav");
        File bgMusicExplodeFile = new File("E:\\JAVA IDEA\\各种小项目\\坦克大战\\tankwar\\musics\\explode.wav");
        File bgMusicExplodeFile2 = new File("musics/老六/哎呀这怎么回事呀.wav");
        File bgMusicExplodeFile3 = new File("E:\\JAVA IDEA\\各种小项目\\坦克大战\\tankwar\\musics\\你在狗叫什么.wav");
        File bgMusicExplodeFile4 = new File("musics/老六/你怎么跟狗一样.wav");
        File bgMusicExplodeFile5 = new File("musics/老六/咦.wav");
        File bgMusicExplodeFile6 = new File("musics/老六/啪哎呀.wav");
        File bgMusicExplodeFile7 = new File("musics/老六/嗷~.wav");
        File bgMusicExplodeFile8 = new File("musics/老六/年轻人不讲武德.wav");
        File bgMusicExplodeFile9 = new File("E:\\JAVA IDEA\\各种小项目\\坦克大战\\tankwar\\musics\\你干嘛哎哟.wav");
        File bgMusicWallFile = new File("E:\\JAVA IDEA\\各种小项目\\坦克大战\\tankwar\\musics\\wall.wav");


        try {

            gameOver.open(overUrl,"");
            gameSucceed.open(succeedUrl,"");

            //开始原版
            AudioInputStream audioInputStreamStart = AudioSystem.getAudioInputStream(bgMusicStartFile);
            start = AudioSystem.getClip();
            start.open(audioInputStreamStart);
            //IKUN版
            AudioInputStream audioInputStreamStart2 = AudioSystem.getAudioInputStream(bgMusicStartFile2);
            start2 = AudioSystem.getClip();
            start2.open(audioInputStreamStart2);
            //失败
            AudioInputStream audioInputStreamOver = AudioSystem.getAudioInputStream(bgMusicOverFile);
            over = AudioSystem.getClip();
            over.open(audioInputStreamOver);
            //胜利
            AudioInputStream audioInputStreamSucceed = AudioSystem.getAudioInputStream(bgMusicSucceedFile);
            succeed = AudioSystem.getClip();
            succeed.open(audioInputStreamSucceed);
            //攻击原版
            AudioInputStream audioInputStreamAttack = AudioSystem.getAudioInputStream(bgMusicAttackFile);
            attack = AudioSystem.getClip();
            attack.open(audioInputStreamAttack);
            //IKUN版
            AudioInputStream audioInputStreamAttack2 = AudioSystem.getAudioInputStream(bgMusicAttackFile2);
            attack2 = AudioSystem.getClip();
            attack2.open(audioInputStreamAttack2);
            AudioInputStream audioInputStreamAttack3 = AudioSystem.getAudioInputStream(bgMusicAttackFile3);
            attack3 = AudioSystem.getClip();
            attack3.open(audioInputStreamAttack3);

            //爆炸原版
            AudioInputStream audioInputStreamStartExplode = AudioSystem.getAudioInputStream(bgMusicExplodeFile);
            explode = AudioSystem.getClip();
            explode.open(audioInputStreamStartExplode);
            //IKUN版
            AudioInputStream audioInputStreamStartExplode2 = AudioSystem.getAudioInputStream(bgMusicExplodeFile2);
            explode2 = AudioSystem.getClip();
            explode2.open(audioInputStreamStartExplode2);
            AudioInputStream audioInputStreamStartExplode3 = AudioSystem.getAudioInputStream(bgMusicExplodeFile3);
            explode3 = AudioSystem.getClip();
            explode3.open(audioInputStreamStartExplode3);
            AudioInputStream audioInputStreamStartExplode4 = AudioSystem.getAudioInputStream(bgMusicExplodeFile4);
            explode4 = AudioSystem.getClip();
            explode4.open(audioInputStreamStartExplode4);
            AudioInputStream audioInputStreamStartExplode5 = AudioSystem.getAudioInputStream(bgMusicExplodeFile5);
            explode5 = AudioSystem.getClip();
            explode5.open(audioInputStreamStartExplode5);
            AudioInputStream audioInputStreamStartExplode6 = AudioSystem.getAudioInputStream(bgMusicExplodeFile6);
            explode6 = AudioSystem.getClip();
            explode6.open(audioInputStreamStartExplode6);
            AudioInputStream audioInputStreamStartExplode7 = AudioSystem.getAudioInputStream(bgMusicExplodeFile7);
            explode7 = AudioSystem.getClip();
            explode7.open(audioInputStreamStartExplode7);
            AudioInputStream audioInputStreamStartExplode8 = AudioSystem.getAudioInputStream(bgMusicExplodeFile8);
            explode8 = AudioSystem.getClip();
            explode8.open(audioInputStreamStartExplode8);
            AudioInputStream audioInputStreamStartExplode9 = AudioSystem.getAudioInputStream(bgMusicExplodeFile9);
            explode9 = AudioSystem.getClip();
            explode9.open(audioInputStreamStartExplode9);

            AudioInputStream audioInputStreamStartMove = AudioSystem.getAudioInputStream(bgMusicMoveFile);
            move = AudioSystem.getClip();
            move.open(audioInputStreamStartMove);
            AudioInputStream audioInputStreamStartWall = AudioSystem.getAudioInputStream(bgMusicWallFile);
            wall = AudioSystem.getClip();
            wall.open(audioInputStreamStartWall);

        }
        catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void playBackground() {
        //循环播放
        move.setFramePosition(0);
        move.loop(Clip.LOOP_CONTINUOUSLY);
    }

    public static void gameSucceedPlay(){
        //gameSucceed.start(true);
        succeed.start();
    }

    public static void hitBasePlay() {
        //gameOver.start(true);
        over.start();
    }

    public static void hitTankPlay() {
        explode9.start();
        explode9.setFramePosition(0);
    }

    public static void startPlay() {
        //start.start();
        //start.setFramePosition(0);
        start2.start();
        start2.setFramePosition(0);
    }

    public static void attackPlay() {
        //attack.start();
        //将进度条调为0
        //attack.setFramePosition(0);
        attack2.start();
        attack2.setFramePosition(0);
    }
    public static void attack2Play() {
        //attack.start();
        //将进度条调为0
        //attack.setFramePosition(0);
        attack3.start();
        attack3.setFramePosition(0);
    }

    public static void explodePlay() {
        Random random = new Random();
        int rnum = random.nextInt(8);
        switch (rnum){
            case 0:
                explode.start();
                explode.setFramePosition(0);
                break;
            case 1:
                explode2.start();
                explode2.setFramePosition(0);
                break;
            case 2:
                explode3.start();
                explode3.setFramePosition(0);
                break;
            case 3:
                explode4.start();
                explode4.setFramePosition(0);
                break;
            case 4:
                explode5.start();
                explode5.setFramePosition(0);
                break;
            case 5:
                explode6.start();
                explode6.setFramePosition(0);
                break;
            case 6:
                explode7.start();
                explode7.setFramePosition(0);
                break;
            case 7:
                explode8.start();
                explode8.setFramePosition(0);
                break;
        }

    }

    public static void movePlay() {
        move.start();
        //循环播放
        move.setFramePosition(0);
        move.loop(Clip.LOOP_CONTINUOUSLY);
    }

    public static void moveStop() {
        move.stop();
    }
    public static void wallPlay() {
        wall.start();
        wall.setFramePosition(0);
    }
}